// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    showModalT:0,
    show:0,
    selectArray: [{
      "id": "10",
      "text": "男"
  }, {
      "id": "21",
      "text": "女"
  }]
  },
  // 事件处理函数
  getInputValue(e){
    var that = this
    console.log(e.detail.value)
    var nickname = e.detail.value
    if(e.detail.value!='')
    {
      this.setData({
        show:1
      })
    }
    that.setData({
      nickname:nickname
    })
  },
  onLoad(options) {
    var that = this;
    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent,
      page: options.page,
    })

  },
  close(){
    var that = this;
    that.setData({
      showModalT:!that.data.showModalT
    })

  },
  next() {
    var that = this;
    that.setData({
      showModalT:!that.data.showModalT
    })
  },
  getPhoneNumber(e) {
    var that = this;
    wx.setStorageSync('nicheng', that.data.nickname)
    
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      wx.setStorageSync('phone', that.data.mobile)
      that.setData({
        mobile: res.result,
      })
      console.log(res.result)
      wx.request({
        url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
        method: 'POST',
        data: {
          activeId: 33,
          mobile: res.result,
          areaCode: that.data.area,
          agent: that.data.geneal,
          pageId: that.data.page
        },
        success: res => {
          console.log(res);
        }
      })
   
        
        // wx.request({ //发送请求
        //   url: 'https://zg99.offcn.com/index/biaodan/register?actid=40245&callback=?', //接收url
        //   data: {
        //     phone: that.data.mobile,
        //     fenxiao: that.data.area,
        //     geneal: that.data.geneal,
        //   }, //接收参数
        //   success(res) {
        //     var jsonStr = res.data;
        //     jsonStr = jsonStr.replace("(", "");
        //     jsonStr = jsonStr.replace(")", "");
        //     if (typeof jsonStr != 'object') {
        //       jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
        //       var theJson = JSON.parse(jsonStr);
        //     }
        //     console.log(theJson)
        //     that.setData({
        //       login: 0
        //     })
        //   }
        // });


      
      })
      if(that.data.show=='1'){
        wx.navigateTo({
          url: '../leixingone/leixingone?area=' + that.data.area + '&agent=' + that.data.agent + '&page=' + that.data.page + '&p_open_id=' + that.data.p_open_id,
        })
      }
      else{
        wx.showToast({
          title: '请先输入您的昵称',
          icon: 'none',
          duration: 2000 //持续的时间
        })
      }

  },
  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log(res)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },
  getUserInfo(e) {
    // 不推荐使用getUserInfo获取用户信息，预计自2021年4月13日起，getUserInfo将不再弹出弹窗，并直接返回匿名的用户个人信息
    console.log(e)
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})